package ynu.edu.achitecturework.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import ynu.edu.achitecturework.dao.CameraDataDAO;
import ynu.edu.achitecturework.entity.CameraData;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
public class CameraService {

    private final CameraDataDAO cameraDataDAO;
    private final DataCollectionService dataCollectionService;

    public List<CameraData> getRecentPhotos(Long deviceId) {
        // 先抓拍新照片
        dataCollectionService.collectCameraData(deviceId);

        // 获取3天前的时间
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -3);
        Date threeDaysAgo = calendar.getTime();

        // 返回最近3天的照片
        return cameraDataDAO.findByDeviceIdAndCreateTimeAfter(deviceId, threeDaysAgo);
    }
}